<?php

function form_validation($form) {

  // District
  distvalidation($form['field_form_dist']['und']['#value']);


 	// minimum length charcter
  	minilength_validation($form['title']['#value'], 5, $form['title']['#title'], 'title');
  	minilength_validation($form['field_form_keywords']['und'][0]['value']['#value'], 5, $form['field_form_keywords']['und'][0]['value']['#title'],'field_form_keywords');
  	minilength_validation($form['field_form_desc']['und'][0]['value']['#value'], 5, $form['field_form_desc']['und'][0]['value']['#title'], 'field_form_desc');

 	//maximum length validation for Title and Description Field
  	maxlength_validation($form['title']['#value'], 255, $form['title']['#title'], 'title');



  // Bad character validations

  chkbadchar($form['title']['#value'], $form['title']['#title'], 'title');
  chkbadchar($form['field_form_ifany']['und'][0]['value']['#value'], $form['field_form_ifany']['und'][0]['value']['#title'], 'field_form_ifany');
  chkbadchar($form['field_form_keywords']['und'][0]['value']['#value'], $form['field_form_keywords']['und'][0]['value']['#title'], 'field_form_keywords');
  chkbadchar($form['field_form_desc']['und'][0]['value']['#value'], $form['field_form_desc']['und'][0]['value']['#title'], 'field_form_desc');
  chkbadchar($form['field_form_othercategory']['und'][0]['value']['#value'], $form['field_form_othercategory']['und'][0]['value']['#title'], 'field_form_othercategory');
  chkbadchar($form['field_form_othertype']['und'][0]['value']['#value'], $form['field_form_othertype']['und'][0]['value']['#title'], 'field_form_othertype');
  // Date Validation

  //check_scheduler_date_expire($form['scheduler_settings']['unpublish_on']['date']['#value'],'unpublish_on');

 	// District
	if(sizeof($form['field_form_dis']['value']['#value'])>1 && $form['field_form_dis']['value']['#value'][0]==0){

        $field=$form['field_form_dis']['value']['#value'][0];
        $field_title=$form['field_form_dis']['#title'];


    form_set_error($field, $field_title . ' field can have either \'ALL\' or \'Other Districts\'');

    }

  // Form Type validtion

  $form_type = $form['field_form_type'];
  if ($form_type['und']['#value'] == 'online') {
    url_validation($form['field_form_avail']['und'][0]['value']['#value']);
  }
  if ($form_type['und']['#value'] == 'download') {

    $filename = $form['field_form_upload']['und'][0]['#file'];
	$filename->filename;
    file_upload_validation_D7($filename->filename,$form['field_form_type']['und']['#title']);
  }

} //form_validaiton()


  function form_presave_validation($node) {
    $reference_url = $node->field_form_avail[0]['value'];
    $node->field_form_avail[0]['value'] = url_validation($reference_url);
  } // function form_presave_validation()





